package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.AppRecord;
import org.apache.ibatis.annotations.*;

public interface AppRecordMapper {
    @Delete({
        "delete from app_record",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into app_record (id, app_type, ",
        "version_name, version_code, ",
        "status, force_update, ",
        "online_time, create_time, ",
        "download_url, description)",
        "values (#{id,jdbcType=BIGINT}, #{appType,jdbcType=TINYINT}, ",
        "#{versionName,jdbcType=VARCHAR}, #{versionCode,jdbcType=INTEGER}, ",
        "#{status,jdbcType=TINYINT}, #{forceUpdate,jdbcType=BIT}, ",
        "#{onlineTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{downloadUrl,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR})"
    })
    int insert(AppRecord record);

    int insertSelective(AppRecord record);

    @Select({
        "select",
        "id, app_type, version_name, version_code, status, force_update, online_time, ",
        "create_time, download_url, description",
        "from app_record",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    AppRecord selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(AppRecord record);

    @Update({
        "update app_record",
        "set app_type = #{appType,jdbcType=TINYINT},",
          "version_name = #{versionName,jdbcType=VARCHAR},",
          "version_code = #{versionCode,jdbcType=INTEGER},",
          "status = #{status,jdbcType=TINYINT},",
          "force_update = #{forceUpdate,jdbcType=BIT},",
          "online_time = #{onlineTime,jdbcType=TIMESTAMP},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "download_url = #{downloadUrl,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(AppRecord record);

    @Select({
            "select",
            "id, app_type, version_name, version_code, status, force_update, online_time, ",
            "create_time, download_url, description",
            "from app_record",
            "where app_type = #{appType,jdbcType=TINYINT} and version_code > #{versionCode,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    AppRecord selectNewVersion(@Param("appType") Integer appType, @Param("versionCode") Integer versionCode);

    @Select({
            "select",
            "id, app_type, version_name, version_code, status, force_update, online_time, ",
            "create_time, download_url, description",
            "from app_record",
            "where app_type = 2 and status = 2 and version_name = #{versionName,jdbcType=VARCHAR} limit 1"
    })
    @ResultMap("BaseResultMap")
    AppRecord selectIosInReviewRecord(@Param("versionName") String versionName);
}